using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    public partial class UserComponent
    {
		//
		// TODO: Add constructor logic here
		//

        /// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public User SelectOneWUserName(string UserName)
        {
            PlacementManager.DAL.User_DAL o = new PlacementManager.DAL.User_DAL();
            o.UserName = UserName;
            DataTable dt = o.SelectOneWUserName().Tables[0];

            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                PlacementManager.User UserToReturn = new PlacementManager.User((int)row["UserId"], (string)row["UserName"], (string)row["FirstName"], (string)row["LastName"], (string)row["IdNumber"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
                return UserToReturn;
            }
            else
            {
                PlacementManager.User UserToReturnEmpty = new PlacementManager.User();
                return UserToReturnEmpty;
            }
        }

        /// <summary>
        /// Gets the available student users for a placement type.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<User> SelectAllAvailableCurrentActiveWPlacementTypeId(int PlacemenTypeId, string sortExpression)
        {
            List<User> listUser = new List<User>();
            PlacementManager.DAL.User_DAL o = new PlacementManager.DAL.User_DAL();

            DataSet ds = o.SelectAllAvailableCurrentActiveWPlacementTypeId(PlacemenTypeId);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listUser.Add(new PlacementManager.User((int)row["UserId"], (string)row["UserName"], (string)row["FirstName"], (string)row["LastName"], (string)row["IdNumber"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listUser.Sort(new UserComparer(sortExpression));
            return listUser;
        }
	}

    
}
